package org.domeos.framework.api.controller.storage;

import org.domeos.basemodel.HttpResponseTemp;
import org.domeos.framework.api.model.storage.Storage;
import org.domeos.framework.api.service.storage.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/api/storage")
@Api("存储相关api")
public class StorageController {

	@Autowired
	StorageService storageService;
	
	@ApiOperation(value="创建存储")
    @ResponseBody
    @RequestMapping(value = "", method = RequestMethod.POST)
    public HttpResponseTemp<?> createStorage(@RequestBody Storage storage){
        return storageService.setStorage(storage);
    }
	
	@ApiOperation(value="删除存储")
    @ResponseBody
    @RequestMapping(value = "/{storageId}", method = RequestMethod.DELETE)
    public HttpResponseTemp<?> deleteStorage(@PathVariable int storageId){
        return storageService.deleteStorage(storageId);
    }
	
	@ApiOperation(value="更新存储")
    @ResponseBody
    @RequestMapping(value = "", method = RequestMethod.PUT)
    public HttpResponseTemp<?> updateStorage(@RequestBody Storage storage){
        return storageService.updateStorage(storage);
    }
	
	@ApiOperation(value="获取存储")
    @ResponseBody
    @RequestMapping(value = "/cluster/{clusterId}", method = RequestMethod.GET)
    public HttpResponseTemp<?> listStorageByClusterId(@PathVariable int clusterId){
        return storageService.listStorageByClusterId(clusterId);
    }
	
	@ApiOperation(value="存储详情")
    @ResponseBody
    @RequestMapping(value = "/{storageId}", method = RequestMethod.GET)
    public HttpResponseTemp<?> getStorageById(@PathVariable int storageId){
        return storageService.getStorageById(storageId);
    }
	
	@ApiOperation(value="获取存储ByCluser和namespace")
    @ResponseBody
    @RequestMapping(value = "/cluster/{clusterId}/namespace/{namespace}", method = RequestMethod.GET)
    public HttpResponseTemp<?> listStorageByClusterIdAndNamespace(@PathVariable int clusterId, @PathVariable String namespace){
        return storageService.getStorageByClusterAndNamespace(clusterId, namespace);
    }
	
	@ApiOperation(value="获取使用存储应用数量")
    @ResponseBody
    @RequestMapping(value = "/{storageId}/deploycount", method = RequestMethod.GET)
    public HttpResponseTemp<?> getDeployCountById(@PathVariable int storageId){
        return storageService.getCountDeployById(storageId);
    }
	
	@ApiOperation(value="存储详情")
    @ResponseBody
    @RequestMapping(value = "/{storageId}/deploydetail", method = RequestMethod.GET)
    public HttpResponseTemp<?> getDeployDetailById(@PathVariable int storageId){
        return storageService.getDeployInstanceById(storageId);
    }
}
